class Solution {
public:
    int triangleNumber(vector<int>& nums) {
        sort(nums.begin(),nums.end());
        int ret=0;
        int n=nums.size()-1;
        while(n>=2)
        {
             int left=0;
             int right=n-1;
             while(left<right)
             {
                 if(nums[left]+nums[right]>nums[n])
                 {
                     ret+=(right-left);
                     right--;
                 }
                 else
                 {
                     left++;
                 }
             }
             n--;
        }
        return ret;
    }
};